<template>
	<view class="">
		<view class="bg-white">
			<scroll-view scroll-y="true" class="scroll-Y">
				<uni-card>
					<view class="p-t-b-10">
						<button @click="on_add(0,'-1')" type="primary" size="mini">新增</button>
					</view>
					<uni-table border stripe type="selection" :type="'2'" @selection-change="selectionData">
						<uni-tr>
							<uni-th align="center" width="30px">id</uni-th>
							<uni-th align="center">文章名称</uni-th>
							<uni-th align="center">创建时间</uni-th>
							<uni-th align="center">管理</uni-th>
						</uni-tr>
						<uni-tr v-for="(vo,index) in list" :key="index">
							<uni-td align="center">
								{{vo.id}}
							</uni-td>
							<uni-td align="center">
								{{vo.name}}
							</uni-td>

							<uni-td align="center">
								{{vo.create_time|getTime}}
							</uni-td>
							<uni-td align="center">
								<view class="">
									<button @click="on_add(vo.id,vo.type)" type="primary" size="mini">编辑</button>
								</view>
								<view class="">
									<button @click="on_del(vo.id,index)" type="warn" size="mini">删除</button>
								</view>
							</uni-td>
						</uni-tr>
					</uni-table>
					<view class="p-20" style="height: 60rpx;">
						<uni-pagination @change="getPage" show-icon="true" :total="total" current="1"
							style="float: left;"></uni-pagination>
					</view>
				</uni-card>
			</scroll-view>
		</view>

		<edit ref="component_edit" @confirm="confirm_edit">
		</edit>
	</view>
</template>

<script>
	import edit from './edit1.vue';
	export default {
		components: {
			edit
		},
		data() {
			return {
				list: [],
				last_page: 0,
				total: 0,
				page: 1,
				total: 0,
				page: 1,


			}
		},
		onLoad() {
			this.init();
		},
		methods: {
			getPage(id) {
				this.page = id.current;
				this.init()
			},
			async init() {
				var that = this;
				let requestParams = {
					page: this.page
				};
				const ret = await this.Banmikeji.Article_list(requestParams);
				if (ret.status == 200) {
					this.list = ret.data.list.data;
					this.total = ret.data.list.total;
				}
			},
			async ajax_del(id) {
				var that = this;
				let requestParams = {
					id: id
				};
				const ret = await this.Banmikeji.Article_dels(requestParams);
				uni.showToast({
					title: ret.msg,
					icon: 'none'
				})
				if (ret.status == 200) {
					that.list = that.list.filter(t => t.id != id);
				}
			},
			on_add(id, type) {

				this.id = id;
				this.$refs.component_edit.init(id)
			},
			on_del(id, index) {
				var that = this;
				if (this.list[index]['type'] == 0) {
					uni.showToast({
						title: '超级管理员无法删除',
						icon: 'none'
					})
					return
				}
				uni.showModal({
					title: '提示',
					content: '确认要删除吗？删除后将不可恢复',
					success: function(res) {
						if (res.confirm) {
							that.ajax_del(id, index);
						}
					}
				});
			},

			confirm_edit() {
				this.page = 1;
				this.init()
			},

		}
	}
</script>

<style>
</style>